package com.xpgk.mvc.productOrgExperience;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.productSet.ProductExperience;
import com.xpgk.mvc.productSet.ProductSetService;

@Service(name = ProductOrgExperienceService.serviceName)
public class ProductOrgExperienceService extends BaseService{
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(ProductSetService.class);

	public static final String serviceName = "productOrgExperienceService";

	
	/**
	 * 添加产品
	 * @param orgid 
	 * @param uid 
	 * @param user
	 * @param organIds
	 * @return
	 */
	public RenderBean addProduct(ProductOrgExperience pes, String uid, String orgid){
		RenderBean result = new RenderBean();
		
		String sql = "SELECT * FROM sb_product_orgexperience where productIds = ? and organIds = ?  and dataStatus = '1'";
		//查询当前机构是否已添加该产品产品
		ProductOrgExperience productOrgExperience = ProductOrgExperience.dao.findFirst(sql,pes.getStr(ProductOrgExperience.column_productIds),orgid);
		if(productOrgExperience!=null){
			result.setCode(ConstantRender.render_error_code);
			result.setMsg("该产品已添加次数，请勿重复添加！");
		}else{
			pes.set(ProductOrgExperience.column_organIds, orgid)
			.set(ProductOrgExperience.column_createDate, new Date())
			.set(ProductOrgExperience.column_createId, uid)
			.set(ProductOrgExperience.column_updateDate, new Date())
			.set(ProductOrgExperience.column_updateId, uid)
			.set(ProductOrgExperience.column_dataStatus, "1");
			
			if(pes.save()){
				result.setMsg("添加成功");
				result.setCode(ConstantRender.render_success_code);
			}else{
				result.setCode(ConstantRender.render_error_code);
				result.setMsg("服务器异常");
			}
		}
	
		return result;
	}
	
	
	/**
	 * 编辑产品
	 * @param user
	 * @param organIds
	 * @return
	 */
	public RenderBean upProduct(ProductOrgExperience pes, String uid, String orgid){
		RenderBean result = new RenderBean();
		pes.set(ProductExperience.column_updateDate, new Date())
		.set(ProductExperience.column_updateId,uid);
		if(pes.update()){
			
				result.setCode(ConstantRender.render_success_code);
			}else{
				result.setCode(ConstantRender.render_error_code);
				result.setMsg("服务器异常，修改失败！");
			}
		
		return result;
	}
	
}
